// DialogSettings.cpp : implementation file
//

#include "stdafx.h"

#include "DialogSettings.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialogSettings dialog


CDialogSettings::CDialogSettings(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogSettings::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogSettings)
	m_linewidth = 0;
	m_isfill = FALSE;
	m_isline = FALSE;
	m_transvalue = _T("");
	//}}AFX_DATA_INIT
}


void CDialogSettings::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogSettings)
	DDX_Control(pDX, IDC_BUTTON_FILLCOLOR, m_fillcolor);
	DDX_Control(pDX, IDC_BUTTON_LINECOLOR, m_linecolor);
	DDX_Text(pDX, IDC_EDIT_LINEWIDTH, m_linewidth);
	DDX_Check(pDX, IDC_CHECK_ISFILL, m_isfill);
	DDX_Check(pDX, IDC_CHECK_ISLINE, m_isline);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogSettings, CDialog)
	//{{AFX_MSG_MAP(CDialogSettings)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_LINEWIDTH, OnDeltaposSpinLinewidth)
	ON_BN_CLICKED(IDC_CHECK_ISFILL, OnCheckIsFill)
	ON_BN_CLICKED(IDC_RADIO_LINE, OnRadioLine)
	ON_BN_CLICKED(IDC_RADIO_CIRC, OnRadioCirc)
	ON_BN_CLICKED(IDC_RADIO_RECT, OnRadioRect)
	ON_BN_CLICKED(IDC_CHECK_ISLINE, OnCheckIsLine)
	ON_BN_CLICKED(IDC_RADIO_LINE2, OnRadioLine2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogSettings message handlers

void CDialogSettings::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void CDialogSettings::OnOK() 
{
	UpdateData(TRUE);

	if (((CButton*)GetDlgItem(IDC_RADIO_LINE))->GetCheck()==1) s_Type=TYPE_LINE;
	if (((CButton*)GetDlgItem(IDC_RADIO_LINE2))->GetCheck()==1) s_Type=TYPE_LINE2;
	if (((CButton*)GetDlgItem(IDC_RADIO_RECT))->GetCheck()==1) s_Type=TYPE_RECT;
	if (((CButton*)GetDlgItem(IDC_RADIO_CIRC))->GetCheck()==1) s_Type=TYPE_CIRC;	

	
	if (((CButton*)GetDlgItem(IDC_RADIO_LINESOLID))->GetCheck()==1) s_LineType=TYPE_LINESOLID;
	if (((CButton*)GetDlgItem(IDC_RADIO_LINEDASH))->GetCheck()==1) s_LineType=TYPE_LINEDASH;
	if (((CButton*)GetDlgItem(IDC_RADIO_LINEDOT))->GetCheck()==1) s_LineType=TYPE_LINEDOT;
	
	if (((CButton*)GetDlgItem(IDC_RADIO_CAPSROUND))->GetCheck()==1) s_CapsType=TYPE_CAPSROUND;
	if (((CButton*)GetDlgItem(IDC_RADIO_CAPSRECT))->GetCheck()==1) s_CapsType=TYPE_CAPSRECT;	

	s_LineWidth=m_linewidth;
	s_IsFill=m_isfill;
	s_LineColor=m_linecolor.currentcolor;
	s_FillColor=m_fillcolor.currentcolor;
	s_IsLine=m_isline;


	CDialog::OnOK();
}

BOOL CDialogSettings::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	((CButton*)GetDlgItem(IDC_RADIO_LINE))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_LINE));
	((CButton*)GetDlgItem(IDC_RADIO_LINE2))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_LINE2));
	((CButton*)GetDlgItem(IDC_RADIO_RECT))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_RECT));
	((CButton*)GetDlgItem(IDC_RADIO_CIRC))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_CIRC));	

	((CButton*)GetDlgItem(IDC_RADIO_CAPSROUND))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_ROUND));	
	((CButton*)GetDlgItem(IDC_RADIO_CAPSRECT))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_SQUARE));

	((CButton*)GetDlgItem(IDC_RADIO_LINESOLID))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_SOLID));
	((CButton*)GetDlgItem(IDC_RADIO_LINEDASH))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_DASH));
	((CButton*)GetDlgItem(IDC_RADIO_LINEDOT))->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_DOT));


	DWORD id=0;
	switch (s_Type)
	{	case TYPE_CIRC: 
			id=IDC_RADIO_CIRC;
			break;
		case TYPE_RECT: 
			id=IDC_RADIO_RECT;
			break;
		case TYPE_LINE: 
			id=IDC_RADIO_LINE;
			break;
		case TYPE_LINE2: 
			id=IDC_RADIO_LINE2;
			break;
	}
	if (id!=0) ((CButton*)GetDlgItem(id))->SetCheck(1);
	
	id=0;
	switch (s_LineType)
	{	case TYPE_LINESOLID: 
			id=IDC_RADIO_LINESOLID;
			break;	
		case TYPE_LINEDASH: 
			id=IDC_RADIO_LINEDASH;
			break;	
		case TYPE_LINEDOT: 
			id=IDC_RADIO_LINEDOT;
			break;	
	}
	if (id!=0) ((CButton*)GetDlgItem(id))->SetCheck(1);


	id=0;
	switch (s_CapsType)
	{	case TYPE_CAPSROUND: 
			id=IDC_RADIO_CAPSROUND;
			break;	
		case TYPE_CAPSRECT: 
			id=IDC_RADIO_CAPSRECT;
			break;	

	}
	if (id!=0) ((CButton*)GetDlgItem(id))->SetCheck(1);


	m_linewidth=s_LineWidth;
	m_isfill=s_IsFill;
	m_linecolor.currentcolor=s_LineColor;
	m_fillcolor.currentcolor=s_FillColor;
	m_isline=s_IsLine;



	UpdateData(FALSE);

	OnCheckIsFill();
	OnCheckIsLine();
	OnRadioLine();







	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDialogSettings::OnDeltaposSpinLinewidth(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;

	UpdateData(TRUE);
	m_linewidth=m_linewidth-pNMUpDown->iDelta;
	if (m_linewidth>100) m_linewidth=100;
	if (m_linewidth<1) m_linewidth=1;
	UpdateData(FALSE);
	
	*pResult = 0;
}

void CDialogSettings::OnCheckIsFill() 
{
	UpdateData(TRUE);
	EnableItem(IDC_BUTTON_FILLCOLOR,m_isfill);
}

void CDialogSettings::OnRadioLine() 
{
/*
	BOOL isLine=(((CButton*)GetDlgItem(IDC_RADIO_LINE))->GetCheck()==1)
			  ||(((CButton*)GetDlgItem(IDC_RADIO_LINE2))->GetCheck()==1);


	EnableItem(IDC_BUTTON_FILLCOLOR,!isLine);
	EnableItem(IDC_CHECK_ISFILL,!isLine);

	if (!isLine) OnCheckIsFill() ;
*/
}

void CDialogSettings::EnableItem(DWORD id, BOOL isEnable)
{
	GetDlgItem(id)->EnableWindow(isEnable);
}

void CDialogSettings::OnRadioCirc() 
{
	OnRadioLine() ;
}

void CDialogSettings::OnRadioRect() 
{
	OnRadioLine() ;	
}

void CDialogSettings::OnCheckIsLine() 
{
	BOOL isLine=(((CButton*)GetDlgItem(IDC_CHECK_ISLINE))->GetCheck()==1);

	EnableItem(IDC_BUTTON_LINECOLOR,isLine);
	EnableItem(IDC_EDIT_LINEWIDTH,isLine);
	EnableItem(IDC_SPIN_LINEWIDTH,isLine);
	EnableItem(IDC_RADIO_CAPSROUND,isLine);
	EnableItem(IDC_RADIO_CAPSRECT,isLine);
	EnableItem(IDC_RADIO_LINEDASH,isLine);
	EnableItem(IDC_RADIO_LINEDOT,isLine);
	EnableItem(IDC_RADIO_LINESOLID,isLine);



}

void CDialogSettings::OnRadioLine2() 
{
	OnRadioLine() ;
}







